<template>
  <div>
    <div class="search_con">
      <div class="iconfont icon-fanhui" @click="prev"></div>
      <div class="header-inp">
        <div class="iconfont icon-sousuo"></div>
        <input type="text" placeholder="晚餐" :value="qqq" />
      </div>
      <div class="header-Icon">
        <span>搜索</span>
      </div>
    </div>

    <div class="result_title">
      <ul>
        <li class="con">菜谱</li>
        <li>笔记</li>
        <li>用户</li>
        <li>商品</li>
        <li>课堂</li>
      </ul>
    </div>

    <div class="result_two">
      <ul>
        <div class="one">
          <li class="tit">综合</li>
          <li>收藏高</li>
          <li>学做多</li>
        </div>
        <div class="two">
          <p>视频<span class="iconfont icon-shipin"></span></p>
        </div>
      </ul>
    </div>

    <div class="result_three">
      <ul>
        <li v-for="(item, index) in keywords" :key="index">
          {{ item }}
        </li>
      </ul>
    </div>

    <div class="result_lists">
      <ul>
        <li v-for="(item, index) in lists" :key="index" @click="push(item.r.id)">
          <div v-if="item.type == 13">
            <div class="left">
              <div class="img">
                <img :src="item.r.img" alt="" />
              </div>
            </div>
            <div class="right">
              <div class="right_text">
                <p>{{ item.r.n }}</p>
                <span
                  >{{
                    item.r.rate == 5
                      ? "5.0分 • "
                      : item.r.rate == 0
                      ? ""
                      : item.r.rate + "分 • "
                  }}
                  {{ item.r.recommend_label }}
                </span>
                <div class="right_four">
                  <ul>
                    <li
                      v-for="(value, index) in item.r.recipe_list_tags"
                      :key="index"
                      :style="{
                        backgroundColor: value.background_start_color,
                        color: value.text_color,
                      }"
                    >
                      {{ value.text }}
                    </li>
                  </ul>
                </div>
                <div class="right_user">
                  <div class="img">
                    <img :src="item.r.a.p" alt="" />
                  </div>
                  <div>
                    <p>{{ item.r.a.n }}</p>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div v-else></div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getRecipeSearchResult } from "../../api/search";
export default {
  data() {
    return {
      keywords: [],
      lists: [],
      qqq:""
    };
  },
  methods:{
     prev(){
        this.$router.go(-1)
      },
      push(id){
       this.$router.push({path:'/details',query: {id:id}})
      }
  },

  created() {
    let queryname = this.$route.query.name;
    this.qqq = queryname;
    getRecipeSearchResult({ keyword:queryname }).then((data) => {
      this.keywords = data.result.secondary_keywords;
      this.lists = data.result.list;
      console.log(data);
    });


  },
};
</script>

<style lang="less">
.search_con {
  display: flex;
  align-items: center;
  margin-top: 30px;
  .iconfont {
    margin-left: 20px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: #151515;
    font-size: 12px;
    line-height: 22px;
    text-align: center;
    font-weight: bold;
  }
  .header-inp {
    position: relative;
    margin-left: 23px;
    display: flex;
    width: 61%;
    height: 30px;
    .iconfont {
      width: 16px;
      height: 16px;
      position: absolute;
      left: 10px;
      top: 0px;
      bottom: 4px;
      margin: auto;
      color: #a1a1a1;
    }
    input {
      width: 100%;
      height: 100%;
      border: transparent;
      outline: none;
      background-color: #f5f5f5;
      border-radius: 5px;
      font-size: 12px;
      line-height: 30px;
      padding-left: 35px;
      color: #a1a1a1;
      &::-webkit-input-placeholder {
        color: #a1a1a1;
      }
    }
  }
  .header-Icon {
    span {
      display: block;
      margin-left: 22px;
      font-size: 12px;
      color: black;
    }
  }
}

.result_title {
  margin-top: 13px;
  ul {
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-bottom: 1px solid #f8f8f8;
    li {
      font-size: 14px;
      line-height: 30px;
      color: #747675;
    }
    .con {
      border-bottom: 3px solid #fbbc1c;
      color: #000000;
    }
  }
}

.result_two {
  border-bottom: 1px solid #f8f8f8;
  ul {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .one {
      display: flex;
      margin-left: 22px;
      li {
        font-size: 14px;
        line-height: 37px;
        color: #747675;
        margin-right: 16px;
      }
      .tit {
        color: black;
      }
    }
    .two {
      margin-right: 23px;
      p {
        font-size: 12px;
        line-height: 37px;
        color: #747675;
        span {
          font-size: 14px;
          color: black;
          margin-left: 5px;
        }
      }
    }
  }
}

.result_three {
  margin-top: 7px;
  margin-left: 15px;
  ul {
    display: flex;
    overflow: auto;
    li {
      font-size: 12px;
      line-height: 24px;
      padding: 0 8px;
      background-color: #fafafa;
      border-radius: 14px;
      color: #9b9b9b;
      flex-shrink: 0;
      margin-right: 8px;
    }
    :nth-child(1) {
      background-color: #ffc533;
      color: black;
    }
  }
  ::-webkit-scrollbar {
    display: none;
  }
}

.result_lists {
  margin: 0 15px;
  margin-top: 15px;
  ul {
    display: flex;
    flex-direction: column;
    li {
      margin-bottom: 15px;
      div {
        display: flex;
        align-items: center;
        .left {
          .img {
            width: 160px;
            height: 113px;
            img {
              width: 100%;
              height: 100%;
              border-radius: 5px;
            }
          }
        }
        .right {
          margin-left: 11px;
          .right_text {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            p {
              font-size: 14px;
              line-height: 24px;
            }
            span {
              display: block;
              font-size: 10px;
              line-height: 20px;
            }
            .right_four {
              ul {
                display: flex;
                flex-direction: row;
                li {
                  font-size: 10px;
                  padding: 0 4px;

                  color: #7c7c7c;
                  background-color: #ffffff;
                  border-radius: 5px;
                  margin-right: 5px;
                }
              }
            }
            .right_user {
              display: flex;
              align-items: center;
              .img {
                width: 16px;
                height: 16px;
                margin-right: 5px;
                img {
                  width: 100%;
                  height: 100%;
                  border-radius: 50%;
                }
              }
              div {
                p {
                  font-size: 12px;
                  line-height: 16px;
                  color: #909090;
                }
              }
            }
          }
        }
      }
    }
  }
}


</style>